"""运行环境的基础配置
"""
import argparse
import sys
import constant
from utils.utils_log import loggerCase
from utils.utils_file import *
from utils.read_config import readconfig

current_time = time.strftime("%Y%m%d%H%M%S")



def command_line_paramaeter():
    """
    接收命令行参数
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('app_dir', help='app路径')
    parser.add_argument('--smoke_mode', help='是否执行性能模块')
    parser.add_argument('--case_type', help='测试用例等级')
    parser.add_argument('--case_num', help='测试用例执行次数')

    args = parser.parse_args()
    smoke_mode = args.smoke_mode
    case_type = args.case_type
    case_num = args.case_num
    print(f'-------{args.app_dir}----------{smoke_mode}---------{case_type}--{case_num}----------')
    return smoke_mode, case_type, case_num


def setup(*args):
    """复制指定的配置文件及存图到指定目录
    """
    print("开始复制ConfigEditor.exe")
    origin_config_editor = constant.file_path + '/ConfigEditor.exe'
    new_config_editor = readconfig.soft_install_path + '/ConfigEditor.exe'
    copy_file(origin_config_editor, new_config_editor)

def pre_setting():
    """卸载软件包并安装新的软件包
    """
    install_path = readconfig.soft_install_path
    arguments = sys.argv
    soft_package = arguments[1] + '.exe'
    print(install_path)
    if os.path.exists(rf'{install_path}\FreeScan Trak.exe'):
        # 除了需要保存的文件，其余都删除
        loggerCase.info("清理环境开始")
        delete_all_except_specified_folder(readconfig.soft_install_path, readconfig.need_save_file)
        time.sleep(10)
    while os.path.exists(rf"{install_path}\FreeScan Trak.exe"):
        loggerCase.info("---等待清理环境中---")
        time.sleep(5)
    loggerCase.info("清理环境结束")
    if not os.path.exists(rf"{install_path}\FreeScan Trak.exe"):
        loggerCase.info(f"安装新的包：{soft_package}")
        os.system(rf"start /wait {soft_package} /S")
    while not os.path.exists(rf"{install_path}\FreeScan Trak.exe"):
        loggerCase.info("新包安装中")
        time.sleep(3)
        loggerCase.info("新包安装成功")


if __name__ == '__main__':
    # pre_setting()
    setup()

